package com.treeeroot.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 */

public class Producer {
    private static final String QUEUE_NAME = "quicker-demo";

    public static void main(String[] args) {

        try {
            //1.获取到链接
            Connection connection = RabbitMQConnection.getConnection();
            //2.创建通道
            Channel channel = connection.createChannel();
            //3.设置消息
            String message = "hello quicker-rabbit-mq111";
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            //4.1关闭通道
            channel.close();
            //4.2关闭链接
            connection.close();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
